<include file="public@header"/>
<style>
	/*table{ border:1px solid #000; width:80%; font-size:1rem; margin-bottom:20px}
	td{border:1px solid #000; padding:0 5px; height:2rem; text-align:center}*/
	tr td input,tr td select{  width:auto;}
	.content_nav .check_info{flex:1; display:flex;flex-direction: column;align-items: center;justify-content: center;}
	.form-horizontal .control-group1 {
		float: left;
		width: 15%;
		margin-bottom: 20px;
	}
	.form-horizontal .control-label {width:80px;}
	.form-horizontal .controls {margin-left:90px;}
	input,select, textarea, .uneditable-input {
		max-width: 580px;
		width:100px;
		min-width:auto;
	}
</style>
</head>
<body>
	<php>$page='';$vo['id']='';</php>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:url('Aftersale/art')}">艺术墓落葬</a></li>
		</ul>

    <form class="form-horizontal " action="{:url('Aftersale/art')}" method="post" enctype="multipart/form-data">
        <fieldset>
        <!--改版画面-->
        <div class="div_title"><span>客户概览</span></div>
        <div class="control-group1-p div_content">
            <fieldset>
                <div class="control-group1">
                    <label class="control-label">客户姓名</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.buyer_name}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">持证类型</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{:cart_type('cart',$result.cart_type)}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">证件号码</label>
                    <div class="controls">
                        <input type="text" class="form-control" style="width:150px;" value="{$result.customer_account}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">联系电话</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.buyer_phone}" disabled>
                    </div>
                </div>
                <div class="control-group1" style="width:40%;">
                    <label class="control-label">联系地址</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.customer_address}" style="width:80%;" disabled>
                    </div>
                </div>
                 <div class="control-group1">
                    <label class="control-label">合同编号</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.contract_sn}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">购买日期</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.gm_start_time}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">打证日期</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.dz_start_time}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">保修期</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.bxq_status}" disabled>
                    </div>
                </div>

                <div class="control-group1">
                    <label class="control-label">当前状态</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.col_status_name}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">维护期</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.whq_status}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">格位编号</label>
                    <div class="controls">
                        <input type="text" class="form-control" value="{$result.tomb_num}" disabled>
                    </div>
                </div>
                <div class="control-group1">
                    <label class="control-label">具体位置</label>
                    <div class="controls">
                        <input type="text" class="form-control" style="width:170px" value="{$result.tomb_region}{$result.tomb_address}" disabled>
                    </div>
                </div>
            </fieldset>
            <!---tab页-->
            <ul class="nav_tabs">
                <li class="active"><a href="javascript:">落葬登记</a></li>
                <li><a href="javascript:">落葬记录</a></li>
            </ul>
            <div class="control-group1-p nav_content">
            	<div class="content_nav">
                	<div class="p_title">
                        <span class="span_title">联系人信息</span>
                    </div>
                    <div class="control-group1-p" style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                    <form action="{:url('Rock/order')}" method="post">
                    <table class="table table-hover table-bordered">
                        <thead>
                            <tr>
                                <th>请选择要使用的墓穴</th>
                                <th>墓穴规制</th>
                                <th>单穴最大尺寸</th>
                                <th>位置</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                            	<td><select name="mb_id" class="form-control">
                                    <foreach name="tomb_list" item="vo">
                                        <option value="{$vo.id}" data-regulation_num="{$vo.regulation_num}" data-regulation_name="{$vo.regulation_name}" data-length="{$vo.pro_length}" data-address="{$vo.address}" >{$vo.pro_name}</option>
                                    </foreach>
                                    </select>
                                </td>
                                <td class="regulation_name">{$tomb_list[0]['regulation_name']|default='0'}</td>
                                <td class="pro_length">{$tomb_list[0]['pro_length']|default='0'}</td>
                                <td class="mb_address">{$tomb_list[0]['address']|default='0'}</td>
                                <td><div class="btn btn-primary" id="check_art_product">查看墓碑</div></td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="pagination">{$page}</div>
                    </form>
                  </div>
                  <div class="p_title">
                        <span class="span_title">逝者信息</span>
                    </div>
                    <div class="control-group1-p" style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                    <form action="{:url('Rock/order')}" method="post">
                    <table class="table table-hover table-bordered">
                        <thead>
                            <tr>
                                <th>逝者姓名</th>
                                <th>性别</th>
                                <th>出生日期</th>
                                <th>逝世日期</th>
                                <th>预约落葬时间</th>
                                <th>收敛形式</th>
                                <th >类型</th>
                                <th>接待人</th>
                                <th>持证人与使用人关系</th>
                                <th>火化证明</th>
                                <th>落葬费</th>
                            </tr>
                        </thead>
                        <tbody id="tomb_regulation">
                        </tbody>
                    </table>
                    <div class="pagination">{$page}</div>
                    </form>
                  </div>
                  <div class="p_title">
                        <span class="span_title">联系人信息</span>
                    </div>
                    <div class="control-group1-p" style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                    <form action="{:url('Rock/order')}" method="post">
                    <table class="table table-hover table-bordered">
                        <thead>
                            <tr>
                                <th>办理人</th>
                                <th>性别</th>
                                <th>手机号码</th>
                                <th></th>
                                <th>关系</th>
                                <th>证件类型</th>
                                <th>证件号码</th>
                                <th>联系地址</th>
                                <th>证件上传</th>
                                <th>经办人</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <input type="hidden"   name="handle[buried_id]" value="{$handle.id|default=''}">
                                    <input type="hidden"   name="handle[service_status]" value="{$handle.service_status|default='0'}">
                                    <input type="text" class="form-control" name="handle[dealer_user]" value="{$handle.dealer_user|default=''}">
                                </td>
                                <td><select name="handle[dealer_sex]" class="form-control">
                                    <option value="男">男</option>
                                    <option value="女">女</option>
                                </select>
                                </td>
                                <td><input type="text" class="form-control" name="handle[dealer_phone]" value="{$handle.dealer_phone|default=''}"></td>
                                <td><input type="checkbox" name="handle[is_sms]" value="1" checked="" >短信通知</td>
                                <td><select name="handle[contact_relation]" class="form-control">
                                    <option value="1">本人办</option>
                                    <option value="2">他人代办</option>
                                </select></td>
                                <td><select name="handle[cart_type]" class="form-control">
                                    <option value="1">身份证</option>
                                    <option value="2">护照</option>
                                    <option value="3">军人证</option>
                                </select></td>
                                <td><input type="text" class="form-control" name="handle[dealer_cart_no]" value="{$handle.dealer_cart_no|default=''}"></td>
                                <td><input type="text" class="form-control" name="handle[dealer_address]" value="{$handle.dealer_address|default=''}"></td>
                                <td>
                                    <php>$img_urls=cmf_get_image_preview_url(isset($handle['cart_file'])?$handle['cart_file']:'');</php>
                                    <input type="hidden" name="handle[cart_file_id]" id="cart_file-file_id" value="{$result.cart_file_id|default=''}">
                                    <input type="hidden" name="handle[cart_file]" id="cart_file" value="{$result.cart_file|default=''}">
                                    <a href="javascript:gpyUploadOneImage('上传证件', '#cart_file','{$result.tomb_num}');">
                                        <h5 class="btn btn-primary">拍照上传</h5>
                                    </a>
                                    <img style="cursor: pointer; height: 50px" onclick="parent.imagePreviewDialog(this.src);"  src="{$img_urls}" class="preview" id="cart_file-preview" />
                                </td>
                                <td>
                                    <input type="hidden" name="handle[handle_name]"   value="{:cmf_get_admin_name()}" >
                                    <input type="text" class="form-control"  value="{:cmf_get_admin_name()}" disabled>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    </form>
                  </div>
                  <div class="form-actions">
                        <div class="btn btn-primary" id="check-btn-save">保存</div>
                    </div>
                </div>
                <div class="content_nav feature" style="">
                	<div class="p_title">
                        <span class="span_title">落葬记录</span>
                    </div>
                    <div class="control-group1-p" style="border:1px solid #e2e2e2; padding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">
                    <form action="{:url('Rock/order')}" method="post">
                    <table class="table table-hover table-bordered" style="max-width: 120% !important;width: 120% !important;">
                        <thead>
                            <tr>
                                <th>逝者姓名</th>
                                <th>性别</th>
                                <th>生卒日期</th>
                                <th>落葬时间</th>
                                <th>收敛形式</th>
                                <th >落葬类别</th>
                                <th >与持证人关系</th>
                                <th >火化证明</th>
                                <th >办理人信息</th>
                                <th >接待部门</th>
                                <th >执行情况</th>
                            </tr>
                        </thead>
                        <tbody>
                        <foreach name="buried_list" item="vo">
                            <tr>
                                <td>{$vo.deceased_name}</td>
                                <td><if ($vo.gender)==1>男  <elseif ($vo.gender)==2/> 女  </if> </td>
                                <td>{$vo.date_birth}-{$vo.date_death}</td>
                                <td>{$vo.funeral_time}</td>
                                <td><if ($vo.convergence_type)==1>骨灰  <elseif ($vo.convergence_type)==2/> 骨殖  </if></td>
                                <td><if ($vo.type)==1>首位落葬  <elseif ($vo.type)==2/> 合葬  </if></td>
                                <td>{$vo.dealer_user}</td>

                                <td><a href="javascript:;" datasrc="{:cmf_get_image_preview_url($vo['cremation_certificate'])}"
                                       onclick="parent.imagePreviewDialog('{:cmf_get_image_preview_url($vo['cremation_certificate'])}');">查看</a> | <a href="{:url('Aftersale/edit',array('id'=>$vo['id']))}">导出</a></td>
                                <td><a  href="javascript:;" class="details" data-url="{:url('Aftersale/edit',array('id'=>$vo['buried_id']))}" data-title="details">查看详情（{$vo.dealer_user}）</a></td>

                                <td>{$vo.handle_name}</td>
                                <td>
                                    <if ($vo.service_status)==1><label style="color:#FF0000">未确认</label>
                                        <elseif ($vo.service_status)==2/>
                                            <label style="color:#87CEFA">已确认</label>
                                            <elseif ($vo.service_status)==3/>
                                                <label style="color:#43CD80">已完成</label>
                                    </if>
                                </td>
                            </tr>
                        </foreach>

                        </tbody>
                    </table>
                    <div class="pagination">{$page}</div>
                    </form>
                  </div>
                  <div class="form-actions">
<!--                        <div class="btn btn-primary" id="check-btn">补打结算单</div><div class="btn btn-primary" id="check-btn">补打登记</div>-->
                  </div>
                </div>
            </div>
        </div>
        </fieldset>
    </form>
    </div>
    <script type="text/javascript">
        var index_type=''
        </script>
	<script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>

<!--    <script type="text/javascript" src="__STATIC__/js/layer/layer.js"></script>-->
    <script type="text/javascript" src="__STATIC__/js/init_base.js?v={:time()}"></script>
	<script type="text/javascript">
        layer.alert('是否已办理墓碑刻制业务？', {icon:3, yes: function (index) {}})
	//切换显示
	$(document).on('click','.nav_tabs li',function(){
		$(this).addClass('active').siblings().removeClass('active');
		var index = $(".nav_tabs li").index(this);
		billtype = index;
		$('.content_nav').eq(index).removeClass("feature").siblings().addClass("feature");
    });

	$(function () {
        var num =  $('select[name=mb_id] option:selected').data('regulation_num');
        var mbid =  $('select[name=mb_id] option:selected').val();
        var index_type=''
        regulation(mbid,num)
    });

    function regulation(mbid,num){
	    var tomb_regulation_tr = $('#tomb_regulation .mb_'+mbid).length;
	    var tr='';
        $.getJSON("{:url('ajax')}?t=6&mb_id="+mbid+"").done(function (returnValue) {
            var josn = returnValue.data;
            console.log(josn.length)
                for (var i = 0; i < num; i++) {
                    var deceased_id = '', deceased_name ='', buied_status = '',
                        date_birth = '', date_death = '', funeral_time = '',
                        relationship_users ='', cremation_certificate = '',cremation_certificate_file_id='',
                        receptionist=''
                        stype_selected_1='',stype_selected_2='',
                        type_selected_1='',type_selected_2='';

                    if (josn[i]) {
                        deceased_id = josn[i].deceased_id, deceased_name = josn[i].deceased_name, buied_status = josn[i].buied_status,
                            date_birth = josn[i].date_birth, date_death = josn[i].date_death, funeral_time = josn[i].funeral_time,
                            relationship_users = josn[i].relationship_users,
                            receptionist = josn[i].receptionist,
                            cremation_certificate = "{:cmf_get_image_preview_url('"+josn[i].cremation_certificate+"')}",
                            cremation_certificate_file_id = josn[i].cremation_certificate_file_id;
                        if(josn[i].convergence_type==1){
                            stype_selected_1 = 'selected';
                        }else if (josn[i].convergence_type==2){
                            stype_selected_2 = 'selected';
                        }
                        if(josn[i].type==1){
                            type_selected_1 = 'selected';
                        }else if (josn[i].type==2){
                            type_selected_2 = 'selected';
                        }

                    }
                    var purchased_file = "上传证件";
                    var purchased_file_id = "#purchased_file" + i + "";
                    tr += "<tr class='mb_"+mbid+"' data-index='"+i+"'><td>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][order_id]' value='{$result.order_id}'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][customer_id]' value='{$result.customer_id}'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][tomb_id]' value='{$result.tomb_id}'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][tomb_num]' value='{$result.tomb_num}'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][mb_id]' value='" + mbid + "'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][deceased_id]' value='"+deceased_id+"'>\n" +
                        "        <input type='text' class='form-control' name='deceased[" + i + "][deceased_name]' value='"+deceased_name+"'style='width: 120px'>\n" +
                        "        <input type='hidden' class='form-control' name='deceased[" + i + "][buied_status]' value='"+buied_status+"' >\n" +
                        "    </td>\n" +
                        "    <td><select name='deceased[" + i + "][gender]' class='form-control'>\n" +
                        "        <option value='1'>男</option>\n" +
                        "        <option value='2'>女</option>\n" +
                        "    </select>\n" +
                        "    </td>\n" +
                        "    <td>\n" +
                        "        <input type='text' class='form-control datacss' autocomplete='off' name='deceased[" + i + "][date_birth]' value='"+date_birth+"'style='width: 120px'>\n" +
                        "    </td>\n" +
                        "    <td>\n" +
                        "        <input type='text' class='form-control datacss' autocomplete='off' name='deceased[" + i + "][date_death]' value='"+date_death+"' style='width: 120px'>\n" +
                        "    </td>\n" +
                        "    <td>\n" +
                        "        <input type='text' class='form-control jsdatetime' autocomplete='off' name='deceased[" + i + "][funeral_time]' value='"+funeral_time+"'>\n" +
                        "    </td>\n" +
                        "    <td><select name='deceased[" + i + "][convergence_type]' class='form-control'>\n" +
                        "            <option value='1' "+stype_selected_1+">骨灰</option>\n" +
                        "            <option value='2' "+stype_selected_2+">骨殖</option>\n" +
                        "    </select>\n" +
                        "    </td>\n" +
                        "    <td>\n" +
                        "        <select name='deceased[" + i + "][type]' id='tomb_cost' class='form-control'>\n" +
                        "                <option value='1' "+type_selected_1+">首位安葬</option>\n" +
                        "                <option value='2'"+type_selected_2+">合葬</option>\n" +
                        "        </select>\n" +
                        "    </td>\n" +
                        "    <td>\n" +
                        "        <select name='deceased[" + i + "][receptionist]' class='form-control'>\n" +
                        "            <foreach name='user_list' item='vou'>\n" +
                        "                    <option value='{$vou.id}' <if condition=' "+receptionist+" == $vou.id'> selected </if> >{$vou.user_nickname}</option>\n" +
                        "            </foreach>\n" +
                        "        </select>\n" +
                        "    </td>\n" +
                        "    <td><input type='text' class='form-control' name='deceased[" + i + "][relationship_users]' value='"+relationship_users+"' style='width: 120px'></td>\n" +
                        "    <td>\n" +
                        "        <input type='hidden' name='deceased[" + i + "][cremation_certificate_file_id]' id='purchased_file" + i + "-file_id' value='"+cremation_certificate_file_id+"'>\n" +
                        "        <input type='hidden' name='deceased[" + i + "][cremation_certificate]' id='purchased_file" + i + "' value='"+cremation_certificate+"'>\n" +
                        "        <a  href=\"javascript:gpyUploadOneImage('" + purchased_file + "','" + purchased_file_id + "','{$result.tomb_num}');\" >\n" +
                        "\t\t<h5 class='btn btn-primary'>拍照上传</h5></a>\n" +
                        "        <img style='cursor: pointer; height: 50px' onclick='parent.imagePreviewDialog(this.src);'  src='"+cremation_certificate+"' class='preview' id='purchased_file" + i + "-preview' /></td>\n" +
                        "    <td>\n" +
                        "        <input type='hidden'  name='deceased[" + i + "][funeral_price]'  value='{$costset.tomb_cost}'>\n" +
                        "        <input type='text'  class='form-control tomb_cost' id='tomb_cost_1' name='deceased[" + i + "][funeral_price]'  value='{$costset.tomb_cost}' disabled style='width: 120px'>\n" +
                        "    </td>\n" +
                        "</tr>";
                // }
            }

            $('#tomb_regulation').html(tr);
            console.log(tomb_regulation_tr)
        })
    }
    // $(".datacss").live("focus", function () {
    //     $(this).datepicker({ dateFormat: "dd/mm/yy", changeMonth: true, changeYear: true });
    // });
    // $("body").delegate(".datacss", "focusin", function(){
    //     $(this).datepicker({ dateFormat: "dd/mm/yy", changeMonth: true, changeYear: true });
    //     $(this).datepicker();
    //     console.log(456)
    // });

    $("#tomb_regulation").on('focus','.datacss',function () {
        var dateInput =$(this);
        if ($(this).length) {
            Wind.use('datePicker', function () {
                dateInput.datePicker({
                    time: false,
                });
            });
        }
    })

    $("#tomb_regulation").on('focus','.jsdatetime',function () {
        var dateInput =$(this);
        if ($(this).length) {
            Wind.use('datePicker', function () {
                dateInput.datePicker({
                    time: true,
                });
            });
        }
    })

    // 提交订单
    $("#check-btn-save").click(function(){
        $.post($("form").attr('action'), $("form").serialize(), function(result){
            if(result.code == 1){
                layer.alert('保存成功。', {icon: 1, yes: function (index) {
                        layer.close(index)
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    });


    $('select[name=mb_id]').change(function () {
        $('.regulation_name').text($(this).find('option:selected').data('regulation_name'));
        $('.pro_length').text($(this).find('option:selected').data('length'));
        $('.mb_address').text($(this).find('option:selected').data('address'));
        var num =  $('select[name=mb_id] option:selected').data('regulation_num');
        var mbid =  $('select[name=mb_id] option:selected').val();
        regulation(mbid,num)
    })

    $('#check_art_product').click(function () {
        var mb_id =  $('select[name=mb_id] option:selected').val();
        var url = "{:url('Admin/Aftersale/ajax')}?t=15&id=" + mb_id;
        RCABase.initBase.ajaxLayerIframeOpen( '查看墓碑详情',url,['90%', '80%'])
        // layer.open({
        //     type: 2,
        //     icon: 4,
        //     title: '查看墓碑详情',
        //     anim: 2,
        //     area: ['90%', '80%'],
        //     content: url
        // });
    })

    </script>

</body>
</html>